<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%--
	auth : Conner
	date : 2012-09-05
	desc : 添加权限
--%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/admin/common/css/style_sub.jsp"></jsp:include>
<script type="text/javascript" src="<%=basePath%>js/public.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/lib/validation/css/livevalidation.css" />
<script type="text/javascript" src="<%=basePath%>js/lib/validation/livevalidation.js"></script>
<script type="text/javascript" src="<%=basePath%>js/lib/jquery/jquery-1.7.1.min.js"></script>
<script language="javascript">
$(function(){
	$("#select1")[0].focus();
	checkAll();
});

function checkAll(){
	var rname = new LiveValidation('rname',{ wait : 500},{onlyOnSubmit:true});
		rname.add( Validate.Presence, {failureMessage: "不能为空!"});
		rname.add( Validate.Length, { maximum: 6 } );

	var parentName = new LiveValidation('parentName',{ wait : 500},{onlyOnSubmit:true});
		parentName.add( Validate.Presence, {failureMessage: "不能为空!"}); 

	var box_width = new LiveValidation('box_width',{ wait : 500},{onlyOnSubmit:true});
		box_width.add( Validate.Presence, {failureMessage: "不能为空!"});
		box_width.add( Validate.Length, { maximum: 4 } );
		box_width.add(Validate.Numericality, { notANumberMessage : "请输入数字!"});
		
	var box_height = new LiveValidation('box_height',{ wait : 500},{onlyOnSubmit:true});
		box_height.add( Validate.Presence, {failureMessage: "不能为空!"});
		box_height.add( Validate.Length, { maximum: 4 } );
		box_height.add(Validate.Numericality, { notANumberMessage : "请输入数字!"});

	var code = new LiveValidation('code',{ wait : 500},{onlyOnSubmit:true});
		code.add( Validate.Presence, {failureMessage: "不能为空!"});
		code.add( Validate.Length, { maximum: 166 } );
		
	var remark = new LiveValidation('remark',{ wait : 500},{onlyOnSubmit:true});
		remark.add( Validate.Presence, {failureMessage: "不能为空!"});
		remark.add( Validate.Length, { maximum: 33 } );
}

function setValue(val){
	G("subSystemId").value = val;
}

//选择父节点
function chooseFRight(){
	var subSysId;  //所属子系统id
	var arr;
	subSysId = G("subSystemId").value;
	if(subSysId == "0" || subSysId != ""){
		var result = window.showModalDialog("<%=basePath %>admin/basic/system/right/right_choose.jsp?time=" + 
				new Date(), subSysId, "dialogWidth:220px; dialogHeight:411px; status:no; resizable:yes;");
		if(typeof(result) == 'string'){
			arr = result.split(",");
			//alert(arr[0]+","+arr[1]+","+arr[2]);
			$("#parentId").val(arr[0]);
			$("#parentName").val(arr[1]);
			setLevel(arr[2]);
		}
	}else{
		alert("请先选择所属子系统");
		G("select1").focus();
	}
}

//切换tr的显示/隐藏
function switchTr(id){
	if(id == 1){
		G("th1").style.display = "block";
		G("td1").style.display = "block";
		G("th2").style.display = "none";
		G("td2").style.display = "none";
	}else if(id == 2){
		G("th2").style.display = "block";
		G("td2").style.display = "block";
		G("th1").style.display = "none";
		G("td1").style.display = "none";
	}
}
function setLevel(flevel){
	var level;
	var str;
	level = Number(flevel) + 1;  //层级  = 父节点层级  + 1
	if(level == 1){
		str = "根菜单";
	}else if(level == 2){
		str = "一级功能";
	}else if(level == 3){
		str = "二级功能";
	}else if(level == 4){
		str = "三级功能";
	}else if(level == 5){
		str = "四级功能";
	}else{
		str = "根菜单";
		level = 1;
	}
	G("leveld").innerHTML = "层级：" + str;
	G("rightLevel").value = level;
}
</script>
</head>
<body>
	<div class="title">添加权限</div>
	<form action="<%=basePath %>basic/sys/right_add.action" id="form" method="post">
		<div class="editorTab">
			<table>
				<tbody>
					<tr>
						<th><font>*</font>所属子系统</th>
						<td>
							<select name="right.sub_id" id="select1" class="downMenu" 
								onchange="javascript:setValue(this.options[this.options.selectedIndex].value);">
								<option value="0">===请选择===</option>
								<s:iterator value="%{listSubSystem}">
									<option value="${id }">${name }</option>
								</s:iterator>
							</select>
							<input type="hidden" id="subSystemId" value="0"/>
						</td>
						<th><font>*</font>所属父节点</th>
						<td>
							<div style="display:inline;float:left;">
								<a href="javascript:void(0);" onclick="javascript:chooseFRight();" title="点击选择">
									<input type="text" id="parentName" readonly="readonly" style="cursor:pointer;"/>
									<input type="hidden" name="right.parent_id" id="parentId"/>
									<img src="<%=basePath%>style/images/ico_11.gif" align="absmiddle"/>
								</a>&nbsp;&nbsp;
							</div>
							<div id="leveld" style="display:inline;float:left;"></div>
							<input type="hidden" name="right.level_" value="1" id="rightLevel" />
						</td>
					</tr>
					<tr>
						<th><font>*</font>菜单名称</th>
						<td>
							<input type="text" name="right.name" id="rname"/>
						</td>
						<th><font>*</font>同级排序号</th>
						<td>
							<select name="right.order_" class="downMenu">
								<option value="0">===请选择===</option>
								<% for(int i = 0 ; i < 100 ; i++){ %>
									<option value="<%=i %>"><%=i %></option>
								<% } %>
							</select>
						</td>
					</tr>
					<tr>
						<th><font>*</font>限制访问</th>
						<td>
							<label><input type="radio" name="right.limit_access" 
								value="1" checked="checked"/>是</label>&nbsp;&nbsp;
							<label><input type="radio" name="right.limit_access" value="2"/>否</label>
						</td>
						<th><font>*</font>外部访问</th>
						<td>
							<label><input type="radio" name="right.external_access" 
								value="1" checked="checked"/>允许</label>&nbsp;&nbsp;
							<label><input type="radio" name="right.external_access" value="2"/>不允许</label>
						</td>
					</tr>
					<tr>
						<th><font>*</font>是否控制子资源权限</th>
						<td>
							<label><input type="radio" name="right.filter_subres" 
								value="1" checked="checked"/>是</label>&nbsp;&nbsp;
							<label><input type="radio" name="right.filter_subres" value="2"/>否</label>
						</td>
						<th><font>*</font>类型</th>
						<td>
							<label><input type="radio" name="right.r_type" 
								value="1" checked="checked"/>菜单</label>&nbsp;&nbsp;
							<label><input type="radio" name="right.r_type" value="2"/>按钮</label>
						</td>
					</tr>
					<tr>
						<th><font>*</font>叶子节点</th>
						<td>
							<label><input type="radio" name="right.is_leaf" 
								value="1" checked="checked"/>是</label>&nbsp;&nbsp;
							<label><input type="radio" name="right.is_leaf" value="2"/>否</label>
						</td>
						<th><font>*</font>当前状态</th>
						<td>
							<label><input type="radio" name="right.r_status" 
								value="1" checked="checked"/>启用</label>&nbsp;&nbsp;
							<label><input type="radio" name="right.r_status" value="2"/>禁用</label>
						</td>
					</tr>
					<tr>
						<th><font>*</font>打开模式</th>
						<td>
							<label><input type="radio" name="right.open_mode" value="1" 
								checked="checked" onclick="javascript:switchTr(1);"/>弹出式</label>&nbsp;&nbsp;
							<label><input type="radio" name="right.open_mode" 
								value="2" onclick="javascript:switchTr(2);"/>非弹出式</label>
						</td>
						<th id="th1"><font>*</font>弹出框窗口宽高(W*H)(像素)</th>
						<td id="td1" colspan="3">
							<input type="text" name="right.box_width" id="box_width" 
								size="4" maxlength="4" value="0" onclick="javascript:this.select();"/>(W)&nbsp;*&nbsp;
							<input type="text" name="right.box_height" id="box_height" 
								size="4" maxlength="4" value="0" onclick="javascript:this.select();"/>(H)(像素)
						</td>
						<th id="th2" style="display:none;">&nbsp;</th>
						<td id="td2" style="display:none;" colspan="3">&nbsp;</td>
					</tr>
					<tr>
						<th><font>*</font>访问地址编码(URL)</th>
						<td>
							<textarea name="right.code" id="code" rows="3" class="downMenu"></textarea>
						</td>
						<th>备注</th>
						<td>
							<textarea name="right.remark" id="remark" rows="3" class="downMenu">无</textarea>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	
		<div class="infoTips">
			加"<font>*</font>"的为必选或必填项
		</div>
		
		<div class="btns">
			<span class="btn"><input type="submit" id="submitBtn" value="添加" /></span>
			<span class="btn">
				<input type="button" id="cancelBtn" value="返回" 
					onclick="javascript:window.history.back();"/>
			</span>
		</div>
	</form>
</body>
</html>
